<?php
/**
 +---------------------------------------<br/>
 * 控制器:首页导航<br/>
 +---------------------------------------
 * @category membership
 * @package web.front.action
 * @author skygreen skygreen2001@gmail.com
 */
class Action_Index extends Action
{
    /**
     * 首页:网站所有页面列表
     */
    public function index()
    {
        $this->loadCss("resources/css/index.css"); 
        $this->loadJs("js/index.js");
        $this->view->set("site_name","美氏博母婴商城");
    }

    //登录
    public function login(){
        $this->loadCss("resources/css/login.css");
        $this->loadJs("js/login.js");
        $msg = "";
        if ($_POST) {
            $cardno = isset($_POST["mobile"])?$_POST["mobile"]:"";
            $passwd = isset($_POST["password"])?$_POST["password"]:"";
            if ($cardno=="") {
                $msg = "手机不能为空";
            }elseif ($passwd=="") {
                $msg = "密码不能为空";
            }else{
                $api = new UtilApi();
                $result = $api->getMember($cardno);
                if($result->code == "A00006"){
                    $data = $result->data;
                    HttpSession::set("cardno",$data->card_no);
                    HttpSession::set("phone",$cardno);
                    $this->redirect("member","info");
                }else{
                    $msg = $result->result;
                }
            }
        }
        $this->view->set("msg",$msg);
        $this->view->set("site_name","会员登录");
    }

    /**
     * 会员卡绑定、激活
     */
    public function req(){
    	if ($_POST) {
    		$realname = isset($_POST["realname"])?$_POST["realname"]:"";
            $mobile = isset($_POST["mobile"])?$_POST["mobile"]:"";
            $password = isset($_POST["password"])?$_POST["password"]:"";
            $pwd = isset($_POST["pwd"])?$_POST["pwd"]:"";
            $email = isset($_POST["email"])?$_POST["email"]:"";
            $birthday = isset($_POST["birthday"])?$_POST["birthday"]:"";
            $gender = isset($_POST["gender"])?$_POST["gender"]:"";
            if($realname == ""){
                $msg = "姓名不能为空";
            }elseif($mobile==""){
                $msg = "手机不能为空";
            }elseif($password ==""){
                $msg = "密码不能为空";
            }elseif($password != $pwd){
                $msg = "密码不一致";
            }else{
                $data = array();
                $data['realname']= $realname;
                $data['mobile']= $mobile;
                $data['password']= $password;
                $data['email']= $email;
                $data['birthday']= $birthday;
                $data['gender']= $gender;
                $api = new UtilApi();
                $result = $api->member_add($data);
                if($result->code == "A00006"){
                    $data = $result->data;
                    HttpSession::set("phone",$mobile);
                    $this->redirect("index","index");
                }else{
                    $msg = $result->result;
                }
            }
    	}
        $this->view->set("msg",$msg);
        $this->view->set("site_name","会员注册");
    }

    public function logout(){
        HttpSession::remove("phone");
        HttpSession::remove("code");
        $this->redirect("index", "login");
    }
}

?>